package errors

import "net/http"

func BadRequest(reason, message string) *Error {
	return New(http.StatusBadRequest, reason, message)
}

func IsBadRequest(err error) bool {
	return Code(err) == http.StatusBadRequest // 400
}

func Unauthorized(reason, message string) *Error {
	return New(http.StatusUnauthorized, reason, message)
}

func IsUnauthorized(err error) bool {
	return Code(err) == http.StatusUnauthorized // 401
}

func Forbidden(reason, message string) *Error {
	return New(http.StatusForbidden, reason, message)
}

func IsForbidden(err error) bool {
	return Code(err) == http.StatusForbidden // 403
}

func NotFound(reason, message string) *Error {
	return New(http.StatusNotFound, reason, message)
}

func IsNotFound(err error) bool {
	return Code(err) == http.StatusNotFound // 404
}

func Conflict(reason, message string) *Error {
	return New(http.StatusConflict, reason, message)
}

func IsConflict(err error) bool {
	return Code(err) == http.StatusConflict // 409
}

func InternalServer(reason, message string) *Error {
	return New(http.StatusInternalServerError, reason, message)
}

func IsInternalServer(err error) bool {
	return Code(err) == http.StatusInternalServerError // 500
}

func ServiceUnavailable(reason, message string) *Error {
	return New(http.StatusServiceUnavailable, reason, message)
}

func IsServiceUnavailable(err error) bool {
	return Code(err) == http.StatusServiceUnavailable // 503
}

func GatewayTimeout(reason, message string) *Error {
	return New(http.StatusGatewayTimeout, reason, message)
}

func IsGatewayTimeout(err error) bool {
	return Code(err) == http.StatusGatewayTimeout // 504
}

func ClientClosed(reason, message string) *Error {
	return New(499, reason, message) // 非http标准
}

func IsClientClosed(err error) bool {
	return Code(err) == 499 // 非http标准
}
